package cn.wolfcode.cms.web.controller;

import cn.wolfcode.cms.domain.ProductSort;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IProductSortService;
import cn.wolfcode.cms.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//商品分类
@Controller
@RequestMapping("productSort")
public class ProductSortController {

    @Autowired
    private IProductSortService productSortService;

    @RequestMapping("")
    public String index() {
        productSortService.list();
        return "productSort/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public Object list(QueryObject qo) {
        return productSortService.query(qo);
    }

    @RequestMapping("listData")
    @ResponseBody
    public Object listData() {
        return productSortService.list();
    }


    //商品分类添加
    @RequestMapping("save")
    @ResponseBody
    public Object save(ProductSort entity) {
        JSONResult result = new JSONResult();
        try {
            productSortService.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("添加失败");
        }
        return result;
    }

    //商品分类编辑
    @RequestMapping("edit")
    @ResponseBody
    public Object edit(ProductSort entity) {
        JSONResult result = new JSONResult();
        try {
            productSortService.update(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("编辑失败");
        }
        return result;
    }

    //商品分类删除
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id) {
        JSONResult result = new JSONResult();
        try {
            productSortService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("删除失败");
        }
        return result;
    }
}
